import request from '@/utils/axios';
import { RoleListResponse, RoleResponse, RoleAllResponse, RolePermissionListResponse, RolePermissionResponse } from './modules/roleModule';

export const apiList = {
    roleList: '/admin/role/list',
    addRole: '/admin/role/add',
    editRole: '/admin/role/edit',
    deleteRole: '/admin/role/delete',
    getRoleAll: '/admin/role/all',
    getRolePermission: '/admin/role/permission',
    updateRolePermission: '/admin/role/permission/update',
};

export const getRoleList = (params: object): Promise<RoleListResponse> => {
    return request({
        url: apiList.roleList,
        method: 'get',
        params: params
    });
};

export const addRole = (params: object): Promise<RoleResponse> => {
    return request({
        url: apiList.addRole,
        method: 'post',
        data: params
    });
};

export const editRole = (params: object): Promise<RoleResponse> => {
    return request({
        url: apiList.editRole,
        method: 'put',
        data: params
    });
};

export const deleteRole = (params: object): Promise<RoleResponse> => {
    return request({
        url: apiList.deleteRole,
        method: 'delete',
        data: params
    });
};

export const getRoleAll = (params: object): Promise<RoleAllResponse> => {
    return request({
        url: apiList.getRoleAll,
        method: 'get',
        params: params
    });
};


// 获取角色权限
export const getRolePermission = (params: object): Promise<RolePermissionListResponse> => {
    return request({
        url: apiList.getRolePermission,
        method: 'get',
        params: params
    });
};

// 更新角色权限
export const updateRolePermission = (params: object): Promise<RolePermissionResponse> => {
    return request({
        url: apiList.updateRolePermission,
        method: 'put',
        data: params
    });
};